package main

import (
    "fmt"
    "github.com/garyburd/redigo/redis"
)


func main() {
    c, err := redis.Dial("tcp", "localhost:6379")
    if err != nil {
        fmt.Println("conn redis failed,", err)
        return
    } 

    fmt.Println("redis conn success")

    defer c.Close()

	_, err = c.Do("Set", "abc1", 100)
    if err != nil {
        fmt.Println(err)
        return
    }

    r, err := redis.Int(c.Do("Get", "abc1"))
    if err != nil {
        fmt.Println("get abc failed,", err)
        return
    }

    fmt.Println(r)


	_, err = c.Do("MSet", "abc", 100, "efg", 300)
    if err != nil {
        fmt.Println(err)
        return
    }

    r2, err2 := redis.Ints(c.Do("MGet", "abc", "efg"))
    if err2 != nil {
        fmt.Println("get abc failed,", err2)
        return
    }

    for _, v := range r2 {
        fmt.Println(v)
    }

	_, err = c.Do("expire", "abc", 10)
    if err != nil {
        fmt.Println(err)
        return
    }

	_, err = c.Do("lpush", "book_list", "abc", "ceg", 300)
    if err != nil {
        fmt.Println(err)
        return
    }

    r3, err3 := redis.String(c.Do("lpop", "book_list"))
    if err3 != nil {
        fmt.Println("get abc failed,", err3)
        return
    }

    fmt.Println(r3)

	_, err = c.Do("HSet", "books", "abc", 100)
    if err != nil {
        fmt.Println(err)
        return
    }

    r4, err4 := redis.Int(c.Do("HGet", "books", "abc"))
    if err != nil {
        fmt.Println("get abc failed,", err4)
        return
    }

    fmt.Println(r4)

}